#ifndef __threadpool_h__
#define __threadpool_h__ 

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

#include "condition.h"


#define GET_THREAD_ID (int)pthread_self()

typedef void *(*task_fuc)(void *arg);

typedef struct task
{
	task_fuc func;
	void *arg;
	struct task *next;

}task_t;


typedef struct threadpool
{
	condition_t ready;
	
	task_t *first;				//任务队列头指针
	task_t *last;				//任务队列尾指针
	
	int counter;				//当前线程数
	int idle;					//正在等待任务的线程数
	int max_threads;			//最大允许的线程数
	int quit;					//销毁线程池的时候置位1

}threadpool_t;


threadpool_t *threadpool_create(int threads);	//线程池创建
void threadpool_destroy(threadpool_t *pool);	//线程池销毁

void threadpool_add_task(threadpool_t *pool, task_fuc func, void *arg);

#endif


